<template>
  <div class="wenzhang">
    <el-row>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <h2 class="jingwen">精彩主题文章</h2>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple-light">
          <span id="geng">
            <router-link to="/health" class="all">查看全部 ></router-link>
          </span>
        </div>
      </el-col>
    </el-row>
    <div class="wencont">
      <router-link
        tag="li"
        v-for="(wendata,index) in wenzhangList"
        v-show="index<3"
        :key="wendata.healthId"
        :to="{ name: 'healthChild', params: { id: wendata.healthId } }"
      >
        <span class="heathId">{{wendata.healthId}}</span>
        <i class="img_1">
          <img :src="'/api/upload/' + wendata.healthImg" alt />
        </i>
        <p>
          <span class="heal">{{wendata.healthTitle}}</span>
          <br />
          <span>{{formateDate(wendata.healthTime)}}</span>
        </p>
      </router-link>
    </div>
  </div>
</template>
<style lang="css" scoped>
h2 {
  font-size: 20px;
  color: #E6A23C;
  font-weight: 700;
  line-height: 48px;
  margin-left: 15px;
}
.wenzhang li {
  width: 33%;
  float: left;
  text-align: center;
}
.wenzhang img {
  width: 90%;
  height: 250px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.6s;
}
.wenzhang img:hover {
  transform: scale(1.1);
}
.wenzhang p {
  width: 90%;
  margin-top: 10px;
  margin-left: 5px;
  line-height: 1.5em;
  text-align: left;
  margin-left: 20px;
  color: rgb(170, 170, 170);
}
.heal {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: black;
  font-size: 18px;
}
.heal:hover {
  color: #E6A23C;
  cursor: pointer;
}
.all {
  text-decoration: none;
  color: black;
  font-size: 18px;
  line-height: 48px;
  float: right;
}
.all:hover {
  color: #E6A23C;
}
</style>
<script>
export default {
  data() {
    return {
      wenzhangList: []
    };
  },
  created() {
    this.$axios
      .get("/api/createNote/getDataNote")
      .then(res => {
        this.wenzhangList = res.data.data;
        // console.log("wenzhangList:", this.wenzhangList);
      })
      .catch(err => {
        console.log("err:", err);
      });
  },
  methods: {
    // 时间格式转换
    formateDate: function(datetime) {
      function addDateZero(num) {
        return num < 10 ? "0" + num : num;
      }
      let d = new Date(datetime);
      let formatdatetime =
        d.getFullYear() +
        "-" +
        addDateZero(d.getMonth() + 1) +
        "-" +
        addDateZero(d.getDate())
        +' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
      return formatdatetime;
    },
  }
};
</script>